<?php
/*
    GUMUD is Extensible Web-based Multi-User Dungeon Software.

    Copyright (C) 2013  White Rabbit

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
include(pathprivate."widgets/widg-lsq/check.php");
if((!isset($_SESSION['widg-lsq-id']) or !isset($_POST['lsq'])) or LSQcheck($_SESSION['widg-lsq-id'],strtolower($_POST['lsq'])) == FALSE) {$_SESSION['error'] = "Security Question was either not answered or not answered correctly. Please try again."; header("location: ".$itt['$varkey']['master']['site']['path']['http']."index.php"); die();}
if(!preg_match("/(\w)+/",$_POST['first'])) {$_SESSION['error'] = "Your avatar's first name has been given with unallowed characters, please check it and try again."; header("location: index.php"); die(); exit(); }
if(!preg_match("/(\w)+/",$_POST['last'])) {$_SESSION['error'] = "Your avatar's last name has been given with unallowed characters, please check it and try again."; header("location: index.php"); die(); exit(); }
if($_POST['token'] != $token) {$_SESSION['error'] = "There was a problem registering your avatar; please retry to register."; header("location: index.php"); die(); exit(); }
if($_POST['tos'] != "Agree"){$_SESSION['error'] = "You must agree to the Terms of Service by checking the checkbox on the registration form; please retry to register."; header("location: index.php"); die(); exit(); }
if($_POST['password'] != $_POST['password2']) {$_SESSION['error'] = "Your given passwords do not match; please retry to register."; header("location: index.php"); die(); exit(); }
if(!isset($_POST['email']) or (strlen($_POST['email']) > 100)) {$_SESSION['error'] = "Email address is missing or exceeds maximum size."; header("location: ".$itt['$varkey']['master']['site']['path']['http']."index.php"); die(); }
if(($_POST['password'] == "") or ($_POST['password2'] == "")) {$_SESSION['error'] = "At least one of your given passwords is blank; please retry to register."; header("location: index.php"); die(); exit(); }
if(preg_match("/(\p{Zs}|\040|\w|\d)+/",$_POST['clothing1'])) { $outfit = $_POST['clothing1'];} else { $outfit = "default"; }

if(mudType == "GAMING") {
if(preg_match("/(\w|\-|\d)+/",$_POST['group1'])) { $class = $_POST['group1'];} else { $class = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; }

if(guildDefinition == "SET") {
$guild = defGuildUUID;
}
else {
if(preg_match("/(\w|\-|\d)+/",$_POST['guild1'])) { $guild = $_POST['guild1'];} else { $guild = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; }
}
}
else {
$class = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
$guild = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
}
$output = createUser($_POST['first'],$_POST['last'],md5($_POST['password']."~".publicsecret),$_POST['email'],$class,$_POST['gender'],$guild,$outfit);

$itx['com-user'][1] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$_POST['first']."&lastname=".$_POST['last']);
$itx['com-user'][2] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=validateuser&uuid=".$itx['com-user'][1]."&passhash=".md5($_POST['password']."~".publicsecret));
if ($itx['com-user'][2] == "validated") {
	$_SESSION['sysmessage'] = "You have create an account successfully! You may now login.";
	setcookie ( "first" , $_POST['first'], unixtime + 24600 , "/" , cookiedomain);
	setcookie ( "last" , $_POST['last'], unixtime + 24600 , "/" , cookiedomain);
	setcookie ( "pass" , md5($_POST['pass']."~".publicsecret), unixtime + 24600 , "/" , cookiedomain);
	$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
touchDAT($itx['com-inner'][3]);
touchInventoryDAT($itx['com-inner'][3]);
updateChat($itx);
	header("location: index.php?com=user&action=account"); die(); exit();
}
else {
	$_SESSION['error'] = "There was a problem with authenticating your avatar. Please check your credentials and try again."; header("location: index.php"); die(); exit();
}



?>
